home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / share / emacs / 19.34 / lisp / tpu-mapper.el.z / tpu-mapper.el
Encoding:
Text File  |  1998-10-28  |  14.6 KB  |  396 lines

  1. ;;; tpu-mapper.el --- Create a TPU-edt X-windows keymap file
  2.  
  3. ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Rob Riepel <riepel@networking.stanford.edu>
  6. ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
  7. ;; Keywords: emulations
  8.  
  9. ;; This file is part of GNU Emacs.
  10.  
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;; GNU General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;;  This emacs lisp program can be used to create an emacs lisp file that
  29. ;;  defines the TPU-edt keypad for emacs running on x-windows.  Please read
  30. ;;  the "Usage" AND "Known Problems" sections before attempting to run this
  31. ;;  program.
  32.  
  33. ;;; Usage:
  34.  
  35. ;;  Simply load this file into the X-windows version of emacs using the
  36. ;;  following command.
  37.  
  38. ;;    emacs -q -l tpu-mapper
  39.  
  40. ;;  The "-q" option prevents loading of your .emacs file (commands therein
  41. ;;  might confuse this program).
  42.  
  43. ;;  An instruction screen showing the TPU-edt keypad will be displayed, and
  44. ;;  you will be prompted to press the TPU-edt editing keys.  Tpu-mapper uses
  45. ;;  the keys you press to create an Emacs Lisp file that will define a
  46. ;;  TPU-edt keypad for your X server.  You can even re-arrange the standard
  47. ;;  EDT keypad to suit your tastes (or to cope with those silly Sun and PC
  48. ;;  keypads).
  49.  
  50. ;;  Finally, you will be prompted for the name of the file to store the key
  51. ;;  definitions.  If you chose the default, TPU-edt will find it and load it
  52. ;;  automatically.  If you specify a different file name, you will need to
  53. ;;  set the variable "tpu-xkeys-file" before starting TPU-edt.  Here's how
  54. ;;  you might go about doing that in your .emacs file.
  55.  
  56. ;;    (setq tpu-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
  57. ;;    (tpu-edt)
  58.  
  59. ;;; Known Problems:
  60.  
  61. ;;  Sometimes, tpu-mapper will ignore a key you press, and just continue to
  62. ;;  prompt for the same key.  This can happen when your window manager sucks
  63. ;;  up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
  64. ;;  Either way, there's nothing that tpu-mapper can do about it.  You must
  65. ;;  press RETURN, to skip the current key and continue.  Later, you and/or
  66. ;;  your local X guru can try to figure out why the key is being ignored.
  67.  
  68. ;;; Code:
  69.  
  70.  
  71. ;;;
  72. ;;;  Make sure we're running X-windows and Emacs version 19
  73. ;;;
  74. (cond
  75.  ((not (and window-system (not (string-lessp emacs-version "19"))))
  76.   (error "tpu-mapper requires running in Emacs 19, with an X display")))
  77.  
  78.  
  79. ;;;
  80. ;;;  Decide whether we're running Lucid Emacs or Emacs itself.
  81. ;;;
  82. (defconst tpu-lucid-emacs19-p (string-match "Lucid" emacs-version)
  83.   "Non-NIL if we are running Lucid Emacs version 19.")
  84.  
  85.  
  86. ;;;
  87. ;;;  Key variables
  88. ;;;
  89. (defvar tpu-kp4 nil)
  90. (defvar tpu-kp5 nil)
  91. (defvar tpu-key nil)
  92. (defvar tpu-enter nil)
  93. (defvar tpu-return nil)
  94. (defvar tpu-key-seq nil)
  95. (defvar tpu-enter-seq nil)
  96. (defvar tpu-return-seq nil)
  97.  
  98.  
  99. ;;;
  100. ;;;  Make sure the window is big enough to display the instructions
  101. ;;;
  102. (if tpu-lucid-emacs19-p (set-screen-size (selected-screen) 80 36)
  103.   (set-frame-size (selected-frame) 80 36))
  104.  
  105.  
  106. ;;;
  107. ;;;  Create buffers - Directions, Keys, Gold-Keys
  108. ;;;
  109. (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
  110. (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
  111. (if (not (get-buffer "Gold-Keys")) (generate-new-buffer "Gold-Keys"))
  112.  
  113.  
  114. ;;;
  115. ;;;  Put headers in the Keys buffer
  116. ;;;
  117. (set-buffer "Keys")
  118. (insert "\
  119. ;;  Key definitions for TPU-edt
  120. ;;
  121. ")
  122.  
  123.  
  124. ;;;
  125. ;;;   Display directions
  126. ;;;
  127. (switch-to-buffer "Directions")
  128. (insert "
  129.     This program prompts you to press keys to create a custom keymap file
  130.     for use with the x-windows version of Emacs and TPU-edt.
  131.  
  132.     Start by pressing the RETURN key, and continue by pressing the keys
  133.     specified in the mini-buffer.  You can re-arrange the TPU-edt keypad
  134.     by pressing any key you want at any prompt.  If you want to entirely
  135.     omit a key, just press RETURN at the prompt.
  136.  
  137.     Here's a picture of the standard TPU/edt keypad for reference:
  138.  
  139.           _______________________    _______________________________
  140.          | HELP  |      Do       |  |       |       |       |       |
  141.          |KeyDefs|               |  |       |       |       |       |
  142.          |_______|_______________|  |_______|_______|_______|_______|
  143.           _______________________    _______________________________
  144.          | Find  |Insert |Remove |  | Gold  | HELP  |FndNxt | Del L |
  145.          |       |       |Sto Tex|  |  key  |E-Help | Find  |Undel L|
  146.          |_______|_______|_______|  |_______|_______|_______|_______|
  147.          |Select |Pre Scr|Nex Scr|  | Page  | Sect  |Append | Del W |
  148.          | Reset |Pre Win|Nex Win|  |  Do   | Fill  |Replace|Undel W|
  149.          |_______|_______|_______|  |_______|_______|_______|_______|
  150.                  |Move up|          |Forward|Reverse|Remove | Del C |
  151.                  |  Top  |          |Bottom |  Top  |Insert |Undel C|
  152.           _______|_______|_______   |_______|_______|_______|_______|
  153.          |Mov Lef|Mov Dow|Mov Rig|  | Word  |  EOL  | Char  |       |
  154.          |StaOfLi|Bottom |EndOfLi|  |ChngCas|Del EOL|SpecIns| Enter |
  155.          |_______|_______|_______|  |_______|_______|_______|       |
  156.                                     |     Line      |Select | Subs  |
  157.                                     |   Open Line   | Reset |       |
  158.                                     |_______________|_______|_______|
  159.  
  160.  
  161. ")
  162. (delete-other-windows)
  163. (goto-char (point-min))
  164.  
  165. ;;;
  166. ;;;  Save <CR> for future reference
  167. ;;;
  168. (cond
  169.  (tpu-lucid-emacs19-p
  170.   (setq tpu-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
  171.   (setq tpu-return (concat "[" (format "%s" (event-key (aref tpu-return-seq 0))) "]")))
  172.  (t
  173.   (message "Hit carriage-return <CR> to continue ")
  174.   (setq tpu-return-seq (read-event))
  175.   (setq tpu-return (concat "[" (format "%s" tpu-return-seq) "]"))))
  176.  
  177.  
  178. ;;;
  179. ;;;  Key mapping functions
  180. ;;;
  181. (defun tpu-lucid-map-key (ident descrip func gold-func)
  182.   (interactive)
  183.   (setq tpu-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
  184.   (setq tpu-key (concat "[" (format "%s" (event-key (aref tpu-key-seq 0))) "]"))
  185.   (cond ((not (equal tpu-key tpu-return))
  186.      (set-buffer "Keys")
  187.      (insert (format"(global-set-key %s %s)\n" tpu-key func))
  188.      (set-buffer "Gold-Keys")
  189.      (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
  190.      (set-buffer "Directions"))
  191.     ;; bogosity to get next prompt to come up, if the user hits <CR>!
  192.     ;; check periodically to see if this is still needed...
  193.     (t
  194.      (format "%s" tpu-key)))
  195.   tpu-key)
  196.  
  197. (defun tpu-emacs-map-key (ident descrip func gold-func)
  198.   (interactive)
  199.   (message "Press %s%s: " ident descrip)
  200.   (setq tpu-key-seq (read-event))
  201.   (setq tpu-key (concat "[" (format "%s" tpu-key-seq) "]"))
  202.   (cond ((not (equal tpu-key tpu-return))
  203.      (set-buffer "Keys")
  204.      (insert (format"(global-set-key %s %s)\n" tpu-key func))
  205.      (set-buffer "Gold-Keys")
  206.      (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
  207.      (set-buffer "Directions"))
  208.     ;; bogosity to get next prompt to come up, if the user hits <CR>!
  209.     ;; check periodically to see if this is still needed...
  210.     (t
  211.      (format "%s" tpu-key)))
  212.   tpu-key)
  213.  
  214. (fset 'tpu-map-key (if tpu-lucid-emacs19-p 'tpu-lucid-map-key 'tpu-emacs-map-key))
  215.  
  216.  
  217. (set-buffer "Keys")
  218. (insert "
  219. ;;  Arrows
  220. ;;
  221. ")
  222. (set-buffer "Gold-Keys")
  223. (insert "
  224. ;;  GOLD Arrows
  225. ;;
  226. ")
  227. (set-buffer "Directions")
  228.  
  229. (tpu-map-key "Up-Arrow"     ""  "'tpu-previous-line"  "'tpu-move-to-beginning")
  230. (tpu-map-key "Down-arrow"   ""  "'tpu-next-line"      "'tpu-move-to-end")
  231. (tpu-map-key "Right-arrow"  ""  "'tpu-forward-char"   "'end-of-line")
  232. (tpu-map-key "Left-arrow"   ""  "'tpu-backward-char"  "'beginning-of-line")
  233.  
  234.  
  235. (set-buffer "Keys")
  236. (insert "
  237. ;;  PF keys
  238. ;;
  239. ")
  240. (set-buffer "Gold-Keys")
  241. (insert "
  242. ;;  GOLD PF keys
  243. ;;
  244. ")
  245. (set-buffer "Directions")
  246.  
  247. (tpu-map-key "PF1"  " - The GOLD key"               "GOLD-map"                 "'keyboard-quit")
  248. (tpu-map-key "PF2"  " - The Keypad Help key"        "'tpu-help"                 "'help-for-help")
  249. (tpu-map-key "PF3"  " - The Find/Find-Next key"     "'tpu-search-again"         "'tpu-search")
  250. (tpu-map-key "PF4"  " - The Del/Undelete Line key"  "'tpu-delete-current-line"  "'tpu-undelete-lines")
  251.  
  252. (set-buffer "Keys")
  253. (insert "
  254. ;;  KP0-9 KP- KP, KP. and KPenter
  255. ;;
  256. ")
  257. (set-buffer "Gold-Keys")
  258. (insert "
  259. ;;  GOLD KP0-9 KP- KP, and KPenter
  260. ;;
  261. ")
  262. (set-buffer "Directions")
  263.  
  264. (tpu-map-key "KP-0"      " - The Line/Open-Line key"               "'tpu-line"                 "'open-line")
  265. (tpu-map-key "KP-1"      " - The Word/Change-Case key"             "'tpu-word"                 "'tpu-change-case")
  266. (tpu-map-key "KP-2"      " - The EOL/Delete-EOL key"               "'tpu-end-of-line"          "'tpu-delete-to-eol")
  267. (tpu-map-key "KP-3"      " - The Character/Special-Insert key"     "'tpu-char"                 "'tpu-special-insert")
  268. (setq tpu-kp4 (tpu-map-key "KP-4"      " - The Forward/Bottom key"               "'tpu-advance-direction"    "'tpu-move-to-end"))
  269. (setq tpu-kp5 (tpu-map-key "KP-5"      " - The Reverse/Top key"                  "'tpu-backup-direction"     "'tpu-move-to-beginning"))
  270. (tpu-map-key "KP-6"      " - The Remove/Insert key"                "'tpu-cut"                  "'tpu-paste")
  271. (tpu-map-key "KP-7"      " - The Page/Do key"                      "'tpu-page"                 "'execute-extended-command")
  272. (tpu-map-key "KP-8"      " - The Section/Fill key"                 "'tpu-scroll-window"        "'tpu-fill")
  273. (tpu-map-key "KP-9"      " - The Append/Replace key"               "'tpu-append-region"        "'tpu-replace")
  274. (tpu-map-key "KP--"      " - The Delete/Undelete Word key"         "'tpu-delete-current-word"  "'tpu-undelete-words")
  275. (tpu-map-key "KP-,"      " - The Delete/Undelete Character key"    "'tpu-delete-current-char"  "'tpu-undelete-char")
  276. (tpu-map-key "KP-."      " - The Select/Reset key"                 "'tpu-select"               "'tpu-unselect")
  277. (tpu-map-key "KP-Enter"  " - The Enter key on the numeric keypad"  "'newline"                  "'tpu-substitute")
  278. ;; Save the enter key
  279. (setq tpu-enter tpu-key)
  280. (setq tpu-enter-seq tpu-key-seq)
  281.  
  282. (set-buffer "Keys")
  283. (insert "
  284. ;;  Editing keypad (find, insert, remove)
  285. ;;                 (select, prev, next)
  286. ;;
  287. ")
  288. (set-buffer "Gold-Keys")
  289. (insert "
  290. ;;  GOLD Editing keypad (find, insert, remove)
  291. ;;                      (select, prev, next)
  292. ;;
  293. ")
  294. (set-buffer "Directions")
  295.  
  296. (tpu-map-key "Find"      " - The Find key on the editing keypad"       "'tpu-search"              "'nil")
  297. (tpu-map-key "Insert"    " - The Insert key on the editing keypad"     "'tpu-paste"               "'nil")
  298. (tpu-map-key "Remove"    " - The Remove key on the editing keypad"     "'tpu-cut"                 "'tpu-store-text")
  299. (tpu-map-key "Select"    " - The Select key on the editing keypad"     "'tpu-select"              "'tpu-unselect")
  300. (tpu-map-key "Prev Scr"  " - The Prev Scr key on the editing keypad"   "'tpu-scroll-window-down"  "'tpu-previous-window")
  301. (tpu-map-key "Next Scr"  " - The Next Scr key on the editing keypad"   "'tpu-scroll-window-up"    "'tpu-next-window")
  302.  
  303. (set-buffer "Keys")
  304. (insert "
  305. ;;  F10-14 Help Do F17
  306. ;;
  307. ")
  308. (set-buffer "Gold-Keys")
  309. (insert "
  310. ;;  GOLD F10-14 Help Do F17
  311. ;;
  312. ")
  313. (set-buffer "Directions")
  314.  
  315. (tpu-map-key "F10"       " - Invokes the Exit function on VT200+ terminals"  "'tpu-exit"                    "'nil")
  316. (tpu-map-key "F11"       " - Inserts an Escape character into the text"      "'tpu-insert-escape"           "'nil")
  317. (tpu-map-key "Backspace" " - Not Delete nor ^H!  Sometimes on the F12 key"   "'tpu-next-beginning-of-line" "'nil")
  318. (tpu-map-key "F13"       " - Invokes the delete previous word function"      "'tpu-delete-previous-word"   "'nil")
  319. (tpu-map-key "F14"       " - Toggles insert/overstrike modes"                "'tpu-toggle-overwrite-mode"  "'nil")
  320. (tpu-map-key "Help"      " - Brings up the help screen, same as PF2"         "'tpu-help"                   "'describe-bindings")
  321. (tpu-map-key "Do"        " - Invokes the COMMAND function"                   "'execute-extended-command"   "'nil")
  322. (tpu-map-key "F17"       ""                                                  "'tpu-goto-breadcrumb"        "'tpu-drop-breadcrumb")
  323.  
  324. (set-buffer "Gold-Keys")
  325. (cond
  326.  ((not (equal tpu-enter tpu-return))
  327.   (insert "
  328. ;;  Minibuffer map additions to make KP_enter = RET
  329. ;;
  330. ")
  331.  
  332.   (insert (format "(define-key minibuffer-local-map %s 'exit-minibuffer)\n" tpu-enter))
  333.   (insert (format "(define-key minibuffer-local-ns-map %s 'exit-minibuffer)\n" tpu-enter))
  334.   (insert (format "(define-key minibuffer-local-completion-map %s 'exit-minibuffer)\n" tpu-enter))
  335.   (insert (format "(define-key minibuffer-local-must-match-map %s 'minibuffer-complete-and-exit)\n" tpu-enter))))
  336.  
  337. (cond
  338.  ((not (or (equal tpu-kp4 tpu-return) (equal tpu-kp5 tpu-return)))
  339.   (insert "
  340. ;;  Minibuffer map additions to allow KP-4/5 termination of search strings.
  341. ;;
  342. ")
  343.  
  344.   (insert (format "(define-key minibuffer-local-map %s 'tpu-search-forward-exit)\n" tpu-kp4))
  345.   (insert (format "(define-key minibuffer-local-map %s 'tpu-search-backward-exit)\n" tpu-kp5))))
  346.  
  347. (insert "
  348. ;;  Define the tpu-help-enter/return symbols
  349. ;;
  350. ")
  351.  
  352. (cond (tpu-lucid-emacs19-p
  353.        (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter-seq))
  354.        (insert (format "(setq tpu-help-return \"%s\")\n" tpu-return-seq))
  355.        (insert "(setq tpu-help-N \"[#<keypress-event N>]\")\n")
  356.        (insert "(setq tpu-help-n \"[#<keypress-event n>]\")\n")
  357.        (insert "(setq tpu-help-P \"[#<keypress-event P>]\")\n")
  358.        (insert "(setq tpu-help-p \"[#<keypress-event p>]\")\n"))
  359.       (t
  360.        (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter))))
  361.  
  362. (append-to-buffer "Keys" 1 (point))
  363. (set-buffer "Keys")
  364.  
  365. ;;;
  366. ;;;  Save the key mapping program
  367. ;;;
  368. (let ((file
  369.        (convert-standard-filename
  370.     (if tpu-lucid-emacs19-p "~/.tpu-lucid-keys" "~/.tpu-keys"))))
  371.   (set-visited-file-name
  372.    (read-file-name (format "Save key mapping to file (default %s): " file) "" file)))
  373. (save-buffer)
  374.  
  375. ;;;
  376. ;;;  Load the newly defined keys and clean up
  377. ;;;
  378. (eval-current-buffer)
  379. (kill-buffer (current-buffer))
  380. (kill-buffer "*scratch*")
  381. (kill-buffer "Gold-Keys")
  382.  
  383. ;;;
  384. ;;;  Let them know it worked.
  385. ;;;
  386. (switch-to-buffer "Directions")
  387. (erase-buffer)
  388. (insert "
  389.     A custom TPU-edt keymap file has been created.
  390.  
  391.     Press GOLD-k to remove this buffer and continue editing.
  392. ")
  393. (goto-char (point-min))
  394.  
  395. ;;; tpu-mapper.el ends here
  396.